package agents.participantagentbehaviours;

import agents.ParticipantAgent;
import jade.core.behaviours.OneShotBehaviour;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

public class RegisterAuctionParticipantServiceBehaviour extends OneShotBehaviour {
	
	private ParticipantAgent owner;

	public RegisterAuctionParticipantServiceBehaviour(ParticipantAgent agent){
		super(agent);
		this.owner = agent;
	}

	@Override
	public void action() {
		System.out.println("Hej");
		DFAgentDescription dfd = new DFAgentDescription();
		dfd.setName(owner.getAID());
		
		ServiceDescription sd = new ServiceDescription();
		sd.setName(owner.getLocalName());
		sd.setType("auctionParticipant");
		
		dfd.addServices(sd);
		
		try {
			DFService.register(myAgent, dfd);
		} catch (FIPAException e) {
			throw new RuntimeException(e);
		}
		
		owner.addBehaviour(new AuctionParticipantBehaviour(owner));
	}
}
